package com.aspose.cells;

class zbvm implements zaik {
   private zahn a;
   private zagu[][] b;
   private zbvj c;
   private int d;
   private int e;
   private int f;
   private boolean g;
   private boolean h;
   private int i;
   private int j;
   private int k;
   private int l;
   private int m;
   private int n;
   private int o;
   private int p;
   private int q;
   private int r;
   private zagu s;
   private boolean t = true;
   private zagu[] u;
   private zagu v;

   public zbvm(zahn var1, zagu var2, int var3, int var4, int var5, int var6, int var7, int var8) {
      this.a = var1;
      this.b = new zagu[var5 - var3 + 1][];
      this.c = new zbvj(this.b.length * this.f);
      this.d = var7;
      this.e = var8;
      if (var2 != null) {
         this.b(var2);
      } else {
         this.t = true;
      }

      this.f = var6 - var4 + 1;
      this.g = false;
      this.h = false;
      this.k = -var3;
      this.l = -var4;
      this.i = 0;
      this.j = 0;
      this.o = Math.max(0, this.k);
      this.q = Math.max(this.l, 0);
      this.r = Math.min(this.f, this.l + this.e);
      if (this.q < this.r) {
         this.p = Math.min(this.b.length, this.k + this.d);
      } else {
         this.p = this.o;
      }

   }

   public zbvm(zagu[][] var1, zahn var2, zagu var3, int var4, int var5, int var6, int var7, int var8, int var9, int var10, boolean var11, boolean var12) {
      this.b = var1;
      this.a = var2;
      if (var3 != null) {
         this.b(var3);
      } else {
         this.t = true;
      }

      this.d = var5;
      this.e = var6;
      this.f = var4;
      this.c = new zbvj(this.b.length * this.f);
      this.k = var7;
      this.l = var8;
      this.g = var11;
      this.h = var12;
      this.i = var9;
      this.j = var10;
      this.o = Math.max(0, this.k);
      this.q = Math.max(this.l, 0);
      this.r = Math.min(this.f, this.l + this.e);
      if (this.q < this.r) {
         this.p = Math.min(this.b.length, this.k + this.d);
      } else {
         this.p = this.o;
      }

   }

   public zaik a(zahn var1) {
      return new zbvm(this.b, var1, this.s, this.f, this.d, this.e, this.k, this.l, this.i, this.j, this.g, this.h);
   }

   public void a() {
      this.m = this.o;
      if (this.m >= this.p) {
         this.n = this.r;
      } else {
         this.u = this.b[this.m];
         if (this.u == null) {
            this.u = new zagu[this.f];
            this.b[this.m] = this.u;
         }

         this.n = this.q - 1;
      }
   }

   public boolean b() {
      if (this.h()) {
         return true;
      } else {
         ++this.m;
         if (this.m >= this.p) {
            return false;
         } else {
            this.u = this.b[this.m];
            this.n = this.q;
            if (this.u == null) {
               this.u = new zagu[this.f];
               this.b[this.m] = this.u;
               this.v = null;
               return true;
            } else {
               this.v = this.u[this.n];
               if (this.v != this.s) {
                  return true;
               } else if (this.h()) {
                  return true;
               } else {
                  ++this.m;
                  if (this.m == this.p) {
                     return false;
                  } else {
                     do {
                        this.u = this.b[this.m];
                        this.n = this.q;
                        if (this.u == null) {
                           this.u = new zagu[this.f];
                           this.b[this.m] = this.u;
                           this.v = null;
                           return true;
                        }

                        this.v = this.u[this.n];
                        if (this.v != this.s) {
                           return true;
                        }

                        if (this.h()) {
                           return true;
                        }

                        ++this.m;
                     } while(this.m != this.p);

                     return false;
                  }
               }
            }
         }
      }
   }

   private boolean h() {
      ++this.n;
      if (this.n >= this.r) {
         return false;
      } else {
         this.v = this.u[this.n];
         if (this.v != this.s) {
            return true;
         } else {
            ++this.n;
            if (this.n == this.r) {
               return false;
            } else {
               do {
                  this.v = this.u[this.n];
                  if (this.v != this.s) {
                     return true;
                  }

                  ++this.n;
               } while(this.n != this.r);

               return false;
            }
         }
      }
   }

   public boolean a(int var1, int var2) {
      var1 += this.k;
      if (var1 >= this.p) {
         this.n = this.r;
         return false;
      } else {
         if (var1 < this.o) {
            var1 = this.o;
            var2 = this.l;
         } else {
            var2 += this.l;
            if (var2 >= this.r) {
               ++var1;
               var2 = this.l;
            }
         }

         if (var2 < this.q) {
            var2 = this.q;
         }

         if (var1 == this.m) {
            if (var2 == this.n) {
               return true;
            }

            this.n = var2;
         } else {
            this.m = var1;
            this.u = this.b[var1];
            this.n = var2;
            if (this.u == null) {
               this.u = new zagu[this.f];
               this.v = null;
               return true;
            }
         }

         this.v = this.u[this.n];
         return this.v != this.s ? true : this.b();
      }
   }

   public boolean a(int var1) {
      return this.a(var1 / this.e, var1 % this.e);
   }

   public zagu c() {
      return this.v;
   }

   public int d() {
      return this.m - this.k;
   }

   public int e() {
      return this.n - this.l;
   }

   public int f() {
      return (this.m - this.k) * this.e + this.n - this.l;
   }

   public zahn a(zaay var1, int var2) {
      if (!this.c.a()) {
         return null;
      } else {
         zagu var3 = null;
         int var5;
         if (var1.k) {
            int var6 = this.a.c();
            int var7 = this.a.d();
            if (this.a.x() && !var1.l.c()) {
               var6 += var1.l.e() - 1;
            }

            if (this.a.y() && !var1.l.d()) {
               var7 += var1.l.f() - 1;
            }

            var5 = var6 * var7;
         } else {
            var5 = this.a.e();
         }

         int var4;
         if (var5 > this.c.b()) {
            if (this.s == null) {
               this.s = this.a.p();
               if (this.s == null) {
                  return null;
               }
            }

            var3 = this.s;
            var4 = var5 - this.c.b() + this.c.c((zagu)null);
         } else {
            var3 = this.c.d();
            var4 = this.c.c(var3);
            if (var3 == null) {
               var3 = this.s;
            }
         }

         if (var4 << 1 < this.c.b()) {
            return new zawi(this.b, this.k, this.l, (int[])null, this.d, this.e, var2, var3, this.i, this.j, this.g, this.h, this.f);
         } else {
            if (var3 == null) {
               var3 = this.s;
            }

            return a(var2, this.b, this.f, var3, this.k, this.l, this.d, this.e, this.i, this.j, this.g, this.h);
         }
      }
   }

   static zahn a(int var0, zagu[][] var1, int var2, zagu var3, int var4, int var5, int var6, int var7, int var8, int var9, boolean var10, boolean var11) {
      int var13 = -1;
      int var14 = 0;

      do {
         zagu[] var12 = var1[var14];

         for(int var15 = 0; var15 < var2; ++var15) {
            if (var12[var15] != var3) {
               var13 = var15;
               break;
            }
         }

         if (var13 > -1) {
            zagu[][] var23 = new zagu[var1.length - var14][];
            zagu[] var16 = a(var13, var12, var2, var3);
            int var17 = var16.length;
            var23[0] = var16;
            int[] var18 = null;
            int var19 = var14;

            for(int var20 = var14 + 1; var20 < var1.length; ++var20) {
               var12 = var1[var20];

               for(int var21 = 0; var21 < var2; ++var21) {
                  if (var12[var21] != var3) {
                     var19 = var20;
                     if (var18 != null) {
                        var18[var20 - var14] = var21;
                     } else if (var21 != var13) {
                        var18 = new int[var1.length - var14];
                        com.aspose.cells.a.c.zc.a((int[])var18, 0, var20 - var14, (int)var13);
                        var18[var20 - var14] = var21;
                        var17 += var13;
                     }

                     var16 = a(var21, var12, var2, var3);
                     var23[var20 - var14] = var16;
                     var17 = Math.max(var17, var21 + var16.length);
                     break;
                  }
               }
            }

            if (var19 == var14) {
               return new zawj(var23[0], false, var5 - var13, var7, var14 - var4, var6, var0, var3, var8, var9, var10, var11);
            }

            if (var19 < var1.length - 1) {
               zagu[][] var24 = new zagu[var19 + 1][];
               System.arraycopy(var23, 0, var24, 0, var24.length);
               var23 = var24;
               if (var18 != null) {
                  int[] var22 = new int[var24.length];
                  System.arraycopy(var18, 0, var22, 0, var22.length);
                  var18 = var22;
               }
            }

            if (var7 == 1) {
               return new zawh(var23, var4 - var14, var18 == null ? var5 - var13 : var5, var18, var6, var0, var3, var8, var9, var10, var11, var17);
            }

            return new zawi(var23, var4 - var14, var18 == null ? var5 - var13 : var5, var18, var6, var7, var0, var3, var8, var9, var10, var11, var17);
         }

         ++var14;
      } while(var14 != var1.length);

      return new zawz(var3, var0, var6, var7);
   }

   private static zagu[] a(int var0, zagu[] var1, int var2, zagu var3) {
      int var4 = var2 - 1;
      if (var4 <= var0) {
         return new zagu[]{var1[var4]};
      } else {
         while(var1[var4] == var3) {
            --var4;
            if (var4 == var0) {
               return new zagu[]{var1[var4]};
            }
         }

         zagu[] var5 = new zagu[var4 - var0 + 1];
         var5[var4 - var0] = var1[var4];
         var5[0] = var1[var0];
         --var4;
         if (var4 > var0) {
            do {
               var5[var4 - var0] = var1[var4];
               --var4;
            } while(var4 != var0);
         }

         return var5;
      }
   }

   public zaik b(int var1) {
      var1 += this.k;
      return (zaik)(var1 >= this.o && var1 < this.p ? new zbvk(this.b[var1], this.a, this.s, this.l, this.e, this.j, false, this.h, this.c) : new zbvn(this.s, 1, this.e));
   }

   public zaik c(int var1) {
      var1 += this.l;
      return (zaik)(var1 >= this.q && var1 < this.q ? new zbvl(this.b, this.a, this.s, this.k, this.l, this.d, this.f, this.i, this.j, this.g, this.h, this.c) : new zbvn(this.s, this.d, 1));
   }

   public void a(zaay var1) {
      if (this.g && var1.g != this.i) {
         this.k += var1.g - this.i;
         this.i = var1.g;
         this.o = Math.max(0, this.k);
         this.p = Math.min(this.b.length, this.k + this.d);
      }

      if (this.h && var1.h != this.j) {
         this.l += var1.h - this.j;
         this.j = var1.h;
         this.q = Math.max(this.l, 0);
         this.r = Math.min(this.f, this.l + this.e);
         if (this.q >= this.r) {
            this.p = this.o;
         }
      }

   }

   public void b(int var1, int var2) {
      var1 += this.k;
      if (var1 > this.m) {
         if (this.t) {
            this.b(this.a.o());
         }

         this.u[this.n] = this.s;
         ++this.n;
         this.c.c();
         if (this.n < this.r) {
            do {
               if (this.u[this.n] == null) {
                  this.u[this.n] = this.s;
                  this.c.c();
               }

               ++this.n;
            } while(this.n != this.r);
         }

         ++this.m;
         this.n = this.q;
         if (this.m < var1) {
            do {
               this.u = this.b[this.m];
               if (this.u == null) {
                  this.u = new zagu[this.f];
                  this.b[this.m] = this.u;
                  com.aspose.cells.a.c.zc.a(this.u, this.q, this.r, this.s);
                  this.c.a(this.r - this.q);
               } else {
                  while(true) {
                     if (this.u[this.n] == null) {
                        this.u[this.n] = this.s;
                        this.c.c();
                     }

                     ++this.n;
                     if (this.n == this.r) {
                        this.n = this.q;
                        break;
                     }
                  }
               }

               ++this.m;
            } while(this.m != var1);
         }

         this.u = this.b[this.m];
         if (this.u == null) {
            this.u = new zagu[this.f];
            this.b[this.m] = this.u;
         }
      }

      var2 += this.l;
      if (this.n < var2) {
         if (this.t) {
            this.b(this.a.o());
         }

         do {
            if (this.u[this.n] == null) {
               this.u[this.n] = this.s;
               this.c.c();
            }

            ++this.n;
         } while(this.n != var2);
      }

      this.v = this.u[this.n];
   }

   public void d(int var1) {
      this.b(var1 / this.e, var1 % this.e);
   }

   public void g() {
      if (this.n < this.r) {
         if (this.t) {
            this.b(this.a.o());
         }

         do {
            if (this.u[this.n] == null) {
               this.u[this.n] = this.s;
               this.c.c();
            }

            ++this.n;
         } while(this.n != this.r);
      }

      ++this.m;
      this.n = this.q;
      if (this.m <= this.p) {
         if (this.t) {
            this.b(this.a.o());
         }

         do {
            this.u = this.b[this.m];
            if (this.u == null) {
               this.u = new zagu[this.f];
               this.b[this.m] = this.u;
               com.aspose.cells.a.c.zc.a(this.u, this.q, this.r, this.s);
               this.c.a(this.r - this.q);
            } else {
               while(true) {
                  if (this.u[this.n] == null) {
                     this.u[this.n] = this.s;
                     this.c.c();
                  }

                  ++this.n;
                  if (this.n == this.r) {
                     this.n = this.q;
                     break;
                  }
               }
            }

            ++this.m;
         } while(this.m <= this.p);
      }

   }

   public void a(zagu var1) {
      this.v = this.c.b(var1);
      this.u[this.n] = this.v;
   }

   public zagu c(int var1, int var2) {
      var1 += this.k;
      if (var1 >= 0 && var1 <= this.p) {
         var2 += this.l;
         if (var2 >= this.q && var2 <= this.r) {
            if (this.b[var1] == null) {
               this.b[var1] = new zagu[this.f];
               return null;
            } else {
               return this.b[var1][var2];
            }
         } else {
            if (this.t) {
               this.b(this.a.o());
            }

            return this.s;
         }
      } else {
         if (this.t) {
            this.b(this.a.o());
         }

         return this.s;
      }
   }

   public void a(int var1, int var2, zagu var3) {
      this.b[var1 + this.k][var2 + this.l] = this.c.b(var3);
   }

   private void b(zagu var1) {
      this.t = false;
      this.s = this.c.a(var1);
   }
}
